package org.iscas.tcse.util;

import org.apache.flink.api.common.serialization.SerializationSchema;
import org.apache.flink.ml.linalg.DenseVector;

import java.nio.charset.StandardCharsets;

public class DenseVectorSerialization implements SerializationSchema<DenseVector> {
    @Override
    public byte[] serialize(DenseVector element) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < element.size(); i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(element.get(i));
        }
        return sb.toString().getBytes(StandardCharsets.UTF_8);
    }
}
